import { BasicColumn } from '/@/components/Table';

import { h } from 'vue';
import { Select, Checkbox, Input, InputNumber } from 'ant-design-vue';

export const columns: BasicColumn[] = [
  {
    title: '流程交办时用于提醒的Email配置',
    dataIndex: 'name',
    colSpan: 2,
  },
  {
    title: '值',
    dataIndex: 'value',
    colSpan: 0,
    customRender: ({ record }) => {
      if (record['type'] === 'checkebox') {
        return h(
          'div',
          {
            style: 'text-align:left',
          },
          h(Checkbox, {
            checked: record['value'],
            onChange: (e) => {
              record['value'] = e.target.checked;
            },
          }),
        );
      } else if (record['type'] === 'select') {
        return h(Select, {
          options: record['options'],
          style: 'width:100%',
          value: record['value'],
          getPopupContainer: () => document.body,
          onChange(value) {
            record['value'] = value;
          },
        });
      } else if (record['type'] === 'inputNumber') {
        return h(InputNumber, {
          value: record['value'],
          onChange: (e) => {
            record['value'] = e.target.value;
          },
        });
      } else {
        return h(Input, {
          value: record['value'],
          onChange: (e) => {
            record['value'] = e.target.value;
          },
          suffix: record['name'] === '邮箱地址' ? '( 例如：123456@qq.com )' : '',
        });
      }
    },
  },
];

export const dataSource = [
  {
    name: '是否启用',
    field: 'flowNotifyByEmail',
    type: 'checkebox',
    value: '',
  },
  {
    name: '邮箱服务器地址',
    field: 'Application.smtpServer',
    type: 'input',
    value: '',
  },
  {
    name: '邮箱服务器端口',
    field: 'Application.smtpPort',
    type: 'inputNumber',
    value: '',
  },
  {
    name: '邮箱登录账号',
    field: 'Application.smtpUser',
    type: 'input',
    value: '',
  },
  {
    name: '邮箱登录密码',
    field: 'Application.smtpPwd',
    type: 'input',
    value: '',
  },
  {
    name: '邮箱地址',
    field: 'Application.email',
    type: 'input',
    value: '',
  },
  {
    name: '是否采用SSL安全套接字连接',
    field: 'Application.smtpSSL',
    type: 'checkebox',
    value: '',
  },
  {
    name: '邮箱服务器编码',
    field: 'Application.smtpCharset',
    type: 'select',
    value: '',
    options: [
      {
        label: '默认',
        value: '',
      },
      {
        label: 'UTF-8',
        value: 'UTF-8',
      },
      {
        label: 'gb2312',
        value: 'gb2312',
      },
      {
        label: '其他',
        value: 'other',
      },
    ],
  },
];
